//验证只能输入数字和小数点
function clearNoNum(obj){
	//先把非数字的都替换掉，除了数字和.
	obj.value = obj.value.replace(/[^\d.]/g,"");
	//必须保证第一个为数字而不是.
	obj.value = obj.value.replace(/^\./g,"");
	//保证只有出现一个.而没有多个.
	obj.value = obj.value.replace(/\.{2,}/g,".");
	//保证.只出现一次，而不能出现两次以上
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
// 检测是否为合法数据
function isNum(str) {
	return (str.search(/^\d+(\.\d+)?$/) != -1);
}
function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g,"");
  }//去掉空格

		var xmlHttp;
		function showCustomer(str)
		{
		  xmlHttp=GetXmlHttpObject();
		  if(xmlHttp==null)
		  {
			   alert("Browser does not support HTTP Request");
			   return ;
		  }
		  var url="/program/admin/catagoryAdvInfo/ajax.jsp";
		  url=url+"?q="+str;
		  xmlHttp.onreadystatechange=stateChanged;
		  xmlHttp.open("GET",url,true);
		  xmlHttp.send(null);
		}
		function stateChanged()
		{
			 if(xmlHttp.readyState==4||xmlHttp.readyState=="complete")
			 {
			  document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
			 }
		}
	function GetXmlHttpObject()
	{
		 var objXMLHttp=null;
		 if(window.XMLHttpRequest)
		 {
		  objXMLHttp=new XMLHttpRequest();
		 }
		 else if(window.ActiveXObject)
		 {
		  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
		 }
	 return objXMLHttp;
	}
 

	function subForm(){

		if(document.getElementById('adv_title').value==""){

				alert('请输入广告名称！');

				document.getElementById('adv_title').focus();

				return false;

			}
			
		var adv_rang="";
			
						if( document.getElementById("class_id"+1).value !=""&&document.getElementById("class_id"+2).value ==""){
							adv_rang += document.getElementById("class_id"+1).value ;	
							}	else
						if( document.getElementById("class_id"+1).value !=""&&document.getElementById("class_id"+2).value !=""&&document.getElementById("class_id"+3).value ==""){
							adv_rang += document.getElementById("class_id"+2).value ;	
							}	else{
							adv_rang += document.getElementById("class_id"+3).value ;	
							}
		 			
				 document.getElementById("adv_rang").value = adv_rang;	
				 
			 if(adv_rang=="")
			  {
			  	alert("请选择广告范围！");
				  return;
			  }
			  
			  
		if(document.getElementById('key_words').value==""){

				alert('请输入广告关键字！');

				document.getElementById('key_words').focus();

				return false;

			}
			if(document.getElementById('price').value==""){

				alert('请输入价格！');

				document.getElementById('price').focus();

				return false;

			}
				if(document.getElementById('s_start_date').value==""){

				alert('请输入开始时间！');

				document.getElementById('s_start_date').focus();

				return false;

			}
				if(document.getElementById('s_end_date').value==""){

				alert('请输入结束时间！');

				document.getElementById('s_end_date').focus();

				return false;

			}
			if(document.getElementById('adv_text').value==""){

				alert('请输入广告文本！');

				document.getElementById('adv_text').focus();

				return false;

			}
			var email=document.getElementById('adv_url').value;
		   var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
								+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" // ftp的user@
								+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
								+ "|" // 允许IP和DOMAIN（域名）
								+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
								+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
								+ "[a-z]{2,6})" // first level domain- .com or .museum
								+ "(:[0-9]{1,4})?" // 端口- :80
								+ "((/?)|" // a slash isn't required if there is no file name
								+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
	var re = new RegExp(strRegex);
	if (email!=''&&!re.test(email))
	{
	alert("链接地址的格式不正确!");
	return;
  }
     document.addForm.submit();
   
	}
	
		function UpdateSubForm(){

		if(document.getElementById('adv_title').value==""){

				alert('请输入广告名称！');

				document.getElementById('adv_title').focus();

				return false;

			}
			
		var adv_rang="";
			
						if( document.getElementById("class_id"+1).value !=""&&document.getElementById("class_id"+2).value ==""){
							adv_rang += document.getElementById("class_id"+1).value ;	
							}	else
						if( document.getElementById("class_id"+1).value !=""&&document.getElementById("class_id"+2).value !=""&&document.getElementById("class_id"+3).value ==""){
							adv_rang += document.getElementById("class_id"+2).value ;	
							}	else{
							adv_rang += document.getElementById("class_id"+3).value ;	
							}
		 			
				 document.getElementById("adv_rang").value = adv_rang;	
				 
				var adv_rang_bak="";
				adv_rang_bak=document.getElementById('adv_rang_bak').value;
			
			 if(adv_rang=="")
			  {
			  	  document.getElementById("adv_rang").value = adv_rang_bak;
			  }else{
			  		document.getElementById("adv_rang").value=adv_rang;
			  	}
			  
		if(document.getElementById('key_words').value==""){

				alert('请输入广告关键字！');

				document.getElementById('key_words').focus();

				return false;

			}
			if(document.getElementById('price').value==""){

				alert('请输入价格！');

				document.getElementById('price').focus();

				return false;

			}
				if(document.getElementById('start_date').value==""){

				alert('请输入开始时间！');

				document.getElementById('start_date').focus();

				return false;

			}
				if(document.getElementById('end_date').value==""){

				alert('请输入结束时间！');

				document.getElementById('end_date').focus();

				return false;

			}
			if(document.getElementById('adv_text').value==""){

				alert('请输入广告文本！');

				document.getElementById('adv_text').focus();

				return false;

			}
		var email=document.getElementById('adv_url').value;
		  myReg = "^((https|http|ftp|rtsp|mms)?://)"+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@
		        + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
		        + "|" // 允许IP和DOMAIN（域名）
		        + "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
		        + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
		        + "[a-z]{2,6})" // first level domain- .com or .museum
		        + "(:[0-9]{1,4})?" // 端口- :80
		        + "((/?)|" // a slash isn't required if there is no file name
		        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
		
		 if (!email.match(myReg)){
			alert("链接地址不正确");
			return false;
 	       }
     document.addForm.submit();
   
	}
	function Num(){
	
		if(isNaN(document.getElementById('price').value)){

				alert('价格必须是数字！');
				document.getElementById('price').focus();
				document.getElementById('price').value="";
		
				return false;

			}
				if(isNaN(document.getElementById('adv_post').value)){

				alert('内容必须是数字！');
				document.getElementById('adv_post').focus();
				document.getElementById('adv_post').value="";
		
				return false;

			}
			
	}
	
function searchForm(){
	 document.indexForm .submit();
}

  function delOneNews(val){
	 
    if(window.confirm('确认删除吗?'))
    {
   	  window.location.href='/doTradeReg.do?pkid='+val+'&bpm_id=7074'; 
    } 
 
}
///////////////////////////////////////////////////////////////////////////

		var type = "12";
		
		function setSecondClass(val) {
			var up_class_id = val;
			Ts_categoryInfo.getCatClassByUpId(up_class_id, type, setSort2);
		}
		
		function setSort2(map_data) {
		 	DWRUtil.removeAllOptions("sort2");
			DWRUtil.addOptions("sort2", map_data);
			document.getElementById("sort3").style.display = "none";
			var item = document.getElementById("sort2").length;
			if (item == 0) {
				document.getElementById("sort2").style.display = "none";
			} else {
				document.getElementById("sort2").style.display = "inline";
			}
		}
		// 设置三级分类
		function setTherdClass(val) {
		 
			var up_class_id = val;
			
			Ts_categoryInfo.getCatClassByUpId(up_class_id, type, setSort3);
		}
		function setSort3(map_data) {
		  
				if (map_data != null) {
					DWRUtil.removeAllOptions("sort3");
					DWRUtil.addOptions("sort3", map_data);
					var item = document.getElementById("sort3").length;
						if (item == 0) {
							document.getElementById("sort3").style.display = "none";
						} else {
							document.getElementById("sort3").style.display = "inline";
						}
			}
		}
		
		function setTypeName1(obj){
				var idx = obj.value;
				document.getElementById("class_id3").value="";
				document.getElementById("class_id2").value="";
				document.getElementById("class_id1").value=idx;
				Ts_categoryInfo.getCatNameById(idx,setClassName1);
		}
		function setClassName1(val) {
				document.getElementById("name3").value = "";
				document.getElementById("name2").value = "";
				document.getElementById("name1").value = val;
		}
		
		function setTypeName2(obj){
				var idx = obj.value;
				document.getElementById("class_id3").value="";
				document.getElementById("class_id2").value=idx;
				Ts_categoryInfo.getCatNameById(idx,setClassName2);
		}
		
		function setClassName2(val) {
				document.getElementById("name3").value = "";
				document.getElementById("name2").value = "&nbsp; &gt; " + val + "&nbsp;";
		}
		function setTypeName3(obj){
				var idx = obj.value;
				document.getElementById("class_id3").value=idx;
				Ts_categoryInfo.getCatNameById(idx,setClassName3);
		}
		function setClassName3(val) {
				document.getElementById("name3").value = "&nbsp; &gt; " + val + "&nbsp;";
		}
		
		function checkClass( val )
		{
				if( CategoryInfo.checkChildren(val) != 0 )
				{
					alert( "请选择完整类型！" );
					return false;
				}
		}
//////////////////////////////////////////////////////////////////


function setSecondClassSe(val) {
	
	var up_class_id = val;
	 
	Ti_channelInfo.getChClassByUpId(up_class_id, setSort22);
}

function setSort22(map_data) {
	
	DWRUtil.removeAllOptions("sort2");
	DWRUtil.addOptions("sort2", map_data);
	document.getElementById("sort3").style.display = "none";
	var item = document.getElementById("sort2").length;
	if (item == 0) {
		document.getElementById("sort2").style.display = "none";
	} else {
		document.getElementById("sort2").style.display = "inline";
	}
}
// 设置三级分类
function setTherdClassSe(val) {
	var up_class_id = val;
	Ti_channelInfo.getChClassByUpId(up_class_id, setSort33);
}
function setSort33(map_data) {
  
	if (map_data != null) {
		DWRUtil.removeAllOptions("sort3");
		DWRUtil.addOptions("sort3", map_data);
		var item = document.getElementById("sort3").length;
		if (item == 0) {
			document.getElementById("sort3").style.display = "none";
		} else {
			document.getElementById("sort3").style.display = "inline";
		}
	}
}


function setTypeName11(obj){
	var idx = obj.value;
	document.getElementById("class_id3").value="";
	document.getElementById("class_id2").value="";
	document.getElementById("class_id1").value=idx;
	Ti_channelInfo.getChName(idx,setClassName11);
}
function setClassName11(val) {
	document.getElementById("name3").value = "";
	document.getElementById("name2").value = "";
	document.getElementById("name1").value = val;
}

function setTypeName22(obj){
	var idx = obj.value;
	document.getElementById("class_id3").value="";
	document.getElementById("class_id2").value=idx;
	Ti_channelInfo.getChName(idx,setClassName22);
}

function setClassName22(val) {
	document.getElementById("name3").value = "";
	document.getElementById("name2").value = "&nbsp; &gt; " + val + "&nbsp;";
}
function setTypeName33(obj){
	var idx = obj.value;
	document.getElementById("class_id3").value=idx;
	Ti_channelInfo.getChName(idx,setClassName33);

	
}
function setClassName33(val) {
	document.getElementById("name3").value = "&nbsp; &gt; " + val + "&nbsp;";
}
